package com.hspedu.newData.dmsxl.dfs;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-15 
 * @Version: 1.0
 */

// todo 超牛逼
public class LC22括号生成 {

    List<String> list = new ArrayList<>();
    public List<String> generateParenthesis(int n) {
        dfs("",n,n);
        return list;
    }

    public void dfs(String str,int left,int right){
        if (left == 0 && right == 0){
            list.add(str);
        }

        if (left>0){
            dfs(str + "(",left-1,right);
        }

        if (left<right){
            dfs(str+")",left,right-1);
        }
    }

}
